package com.tree.service.impl;

import com.tree.dao.FlowerDao;
import com.tree.entity.Flower;
import com.tree.service.FlowerService;
import com.tree.util.PageCal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class FlowerServiceImpl implements FlowerService {

    @Autowired
    private FlowerDao flowerDao;

    @Override
    public List<Flower> queryAll(int pageIndex, int rowSize) {

        //将页数转换为行数
        int rowIndex = PageCal.calculateRowIndex(pageIndex,rowSize);
        List<Flower> list = new ArrayList<>();
        list = flowerDao.queryAll(rowIndex,rowSize);
        return list;
    }

    @Override
    public Flower query(String flowerName) {
        Flower flower;
        flower = flowerDao.query(flowerName);
        if (flower != null && flower.getFlowerName() != null)
            return flower;
        return null;
    }
    @Override
    public List<Flower> querySearch(String flowerName) {
        return flowerDao.querySearch(flowerName);
    }
}
